﻿/**
 * @author sminutoli
 * version 1.0
 * 
 */
import com.dinmax.flash.draw.control.loader.*
import com.dinmax.flash.draw.common.Point

class Loader
extends com.dinmax.flash.draw.control.Control
implements LoaderListener {
	
	private var view:LoaderView;
	private var base:MovieClip;
	private var movieLoader:MovieClipLoader;
		
	public function Loader(parente:MovieClip, view:LoaderView) {
		super(parente);
		this.view = view;
	};
	public function draw():Void {
		view.reset();
		//Creo el movieBase
		removeMovieClip(base);
		base=createMovieClip();
		base._x=getLocation().getX();
		base._y=getLocation().getY();
		reDraw();
	};
	public function reDraw():Void {
		//tengo que setearle propiedades porque el flash es puto
		base.width=getSize().getX();
		base.height=getSize().getY();
		
		//dibujo el borde el fondo y seteo el texto
		view.border(base);
		
	};
	
	public function setSize(size:Point):Void{
		super.setSize(size);
		if(base){
			//trace("PressButtonControl.as | voy a llamar al reDraw");
			reDraw();
		}
	}
	
	public function onLoadStart(target:MovieClip):Void{
		view.setText("Loading");
	};
	public function onLoadProgress(target:MovieClip, loaded:Number, total:Number):Void{
		var nPercent:Number = Math.round(loaded*100/total);
		trace("Loader.as | onLoadProgress() | target: "+target+" percent: "+nPercent);
		view.setPos(nPercent);
		view.setText("Loading "+nPercent+"%");
	};
	public function onLoadComplete(target:MovieClip, httpStatus:Number):Void{
		view.setPos(100);
		view.setText("Load complete");
	};
	public function onLoadInit(target:MovieClip):Void{
		
	};
	public function onLoadError(target:MovieClip, errorCode:String, httpStatus:Number):Void{
		view.error("Load Error");
	};
	
};